using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberVideoDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberVideoDA()
		{
		}

		public MemberVideoDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberVideo table.
		/// </summary>
		public  int Insert(MemberVideo memberVideo)
		{
			ValidationUtility.ValidateArgument("memberVideo", memberVideo);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberVideo.TenantID),
				new SqlParameter("@ProfileID", memberVideo.ProfileID),
				new SqlParameter("@Title", memberVideo.Title),
				new SqlParameter("@VideoURL", memberVideo.VideoURL),
				new SqlParameter("@IsApproved", memberVideo.IsApproved),
				new SqlParameter("@AddedOn", memberVideo.AddedOn)
			};

			memberVideo.VideoID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberVideoInsert", parameters));
			return memberVideo.VideoID;
		}

		/// <summary>
		/// Updates a record in the MemberVideo table.
		/// </summary>
		public  int Update(MemberVideo memberVideo)
		{
			ValidationUtility.ValidateArgument("memberVideo", memberVideo);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@VideoID", memberVideo.VideoID),
				new SqlParameter("@TenantID", memberVideo.TenantID),
				new SqlParameter("@ProfileID", memberVideo.ProfileID),
				new SqlParameter("@Title", memberVideo.Title),
				new SqlParameter("@VideoURL", memberVideo.VideoURL),
				new SqlParameter("@IsApproved", memberVideo.IsApproved),
				new SqlParameter("@AddedOn", memberVideo.AddedOn)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberVideoUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberVideo table by its primary key.
		/// </summary>
		public  int Delete(int videoID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@VideoID", videoID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberVideoDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberVideo table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberVideoDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberVideo table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberVideoDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberVideo table.
		/// </summary>
		public  MemberVideo Select(int videoID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@VideoID", videoID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberVideoSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberVideo(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberVideo table.
		/// </summary>
		public  List<MemberVideo> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberVideoSelectAll", parameters))
			{
				List<MemberVideo> memberVideoList = new List<MemberVideo>();
				while (dataReader.Read())
				{
					MemberVideo memberVideo = MakeMemberVideo(dataReader);
					memberVideoList.Add(memberVideo);
				}

				return memberVideoList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberVideo table by a foreign key.
		/// </summary>
		public  List<MemberVideo> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberVideoSelectAllByProfileID", parameters))
			{
				List<MemberVideo> memberVideoList = new List<MemberVideo>();
				while (dataReader.Read())
				{
					MemberVideo memberVideo = MakeMemberVideo(dataReader);
					memberVideoList.Add(memberVideo);
				}

				return memberVideoList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberVideo table by a foreign key.
		/// </summary>
		public  List<MemberVideo> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberVideoSelectAllByTenantID", parameters))
			{
				List<MemberVideo> memberVideoList = new List<MemberVideo>();
				while (dataReader.Read())
				{
					MemberVideo memberVideo = MakeMemberVideo(dataReader);
					memberVideoList.Add(memberVideo);
				}

				return memberVideoList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberVideo class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberVideo MakeMemberVideo(SqlDataReader dataReader)
		{
			MemberVideo memberVideo = new MemberVideo();
			memberVideo.VideoID = SqlClientUtility.GetInt32(dataReader, "VideoID", 0);
			memberVideo.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberVideo.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberVideo.Title = SqlClientUtility.GetString(dataReader, "Title", String.Empty);
			memberVideo.VideoURL = SqlClientUtility.GetString(dataReader, "VideoURL", String.Empty);
			memberVideo.IsApproved = SqlClientUtility.GetString(dataReader, "IsApproved", String.Empty);
			memberVideo.AddedOn = SqlClientUtility.GetString(dataReader, "AddedOn", String.Empty);

			return memberVideo;
		}

		#endregion
	}
}
